package com.mmf.ancientcostume.presenter.imp.goods;

import android.util.Log;

import com.mmf.ancientcostume.activity.CommentListActivity;
import com.mmf.ancientcostume.base.presenter.BasePresenter;
import com.mmf.ancientcostume.model.Comment;
import com.mmf.ancientcostume.service.home.HomeService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import rx.Subscription;
import rx.functions.Action1;

/**
 * Created by MMF on 2017-08-03.
 */

public class CommentListPresenterImp extends BasePresenter<CommentListActivity> {
    private HomeService mHomeService;
    private List<Comment> list = new ArrayList<>();

    public CommentListPresenterImp() {
        mHomeService = new HomeService();
    }


    public void getCommentList(Map<String, Object> params, final int pageNo) {
        showLoadingDialog();
        Subscription subscription =
                mHomeService.getCommentList(params).doOnNext(new Action1<List<Comment>>() {
                    @Override
                    public void call(List<Comment> remindDTOs) {
                        if (remindDTOs.size() == 0) {
                            showToast("没有更多的数据！");
                        }
                        if (pageNo == 1) {
                            list = remindDTOs;
                        } else {
                            list.addAll(remindDTOs);
                        }
                        view.onSuccess(list);
                    }
                }).subscribe(newSubscriber(new Action1<List<Comment>>() {
                    @Override
                    public void call(List<Comment> remindDTOs) {
                        Log.e("********test", "111111");
                    }
                }));
        mCompositeSubscription.add(subscription);
    }

}
